<?php

/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-06 00:16:08 +0200 (Sun, 06 Jul 2008) $
 * $Rev: 1270 $
 * $Author: gavinspearhead $
 * $Id: exception.php 1270 2008-07-05 22:16:08Z gavinspearhead $
 */

// This is an include-only file:
if (!defined('ORIGINAL_PAGE')) die('This file cannot be accessed directly.');
$pathexc = realpath(dirname(__FILE__));

require_once "$pathexc/../functions/smarty.php";


define ('DEFAULT_MSG', 'Our sincere apologies but a fatal error has occurred. For more information, turn on DEBUG mode by editing defines.php.');

// Default exception handler:
function exception_handler(exception $exception) {
	global $__message, $LN, $title, $config, $smarty;
	$smarty->assign('menu',         generate_menu($LN));
	$smarty->assign('title',        $LN['fatal_error_title']);

	$pathexh = realpath(dirname(__FILE__));
	$thisScript = $_SERVER['PHP_SELF'];
	if (strpos($thisScript, 'ajax_') === FALSE) {
		// Not an ajax-script, so display entire page
		if (debug_match(DEBUG_CLIENT, $config['urdd_debug_level']))
			$__message[] = $exception->getMessage();
		else
			$__message[] = DEFAULT_MSG;

		$title = 'Exception!';
		$smarty->assign('__message', $__message);
	} else {
		// Ajax script, output bare html
		if (debug_match(DEBUG_CLIENT, $config['urdd_debug_level']))
			$__message[] = $exception->getMessage();
		else
			$__message[] = DEFAULT_MSG;
		$smarty->assign('__message', $__message);
		$smarty->assign('link', NULL);
		$smarty->assign('link_msg', NULL);

	}
	$smarty->display('fatal_error.tpl');
	die();
}

set_exception_handler('exception_handler');

?>
